<template>
  <el-dialog
      :model-value="props.visible"
      title="参数详情"
      width="90%"
      top="8vh"
      :before-close="handleClose"
      @update:model-value="emit('update:visible', $event)"
  >
    <!-- 表格展示 -->
    <el-table :data="detailList" border stripe max-height="60vh">
      <el-table-column prop="paramOrder" label="序号" width="70"/>
      <el-table-column prop="paramCode" label="参数代号" width="120"/>
      <el-table-column prop="paramName" label="参数名称" width="220px"/>
      <el-table-column prop="paramDefine" label="参数定义" width="420px"/>


      <el-table-column prop="paramLen" label="参数长度" width="120"/>
      <el-table-column prop="paramType" label="参数类型" width="150"/>
      <el-table-column prop="processMethod" label="处理方式"/>
      <el-table-column prop="defaultValue" label="使用参数值"  width="150"/>
      <el-table-column prop="unit" label="单位" width="150"/>
      <el-table-column prop="dimension" label="量纲" width="150"/>
      <el-table-column prop="description" label="说明" min-width="200"/>
    </el-table>

    <template #footer>
      <el-button @click="handleClose">关闭</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, watch } from 'vue'


import { ElMessage } from 'element-plus'
import {chaXunYiFaZhiLingCanShuSerive} from "../../../api/satellite/SingleInstructionSending.js";

const props = defineProps({
  visible: Boolean,
  sentCommandId: { type: [String, Number], default: null }
})
const emit = defineEmits(['update:visible'])

// 数据
const detailList = ref([])

// 监听弹窗打开
watch(() => props.visible, (val) => {
  if (val && props.sentCommandId) {
    loadDetail()
  }
})

// 查询
const loadDetail = async () => {
  try {

    const param = {
      sentCommandId: props.sentCommandId,
    }

    await chaXunYiFaZhiLingCanShuSerive(param).then((response) => {
      console.log(response)
      if (response.code === 200) {
        detailList.value = response.rows
      } else {
        ElMessage.error(response.msg || '加载失败')
      }
    }).catch((error) => {
      ElMessage.error('获取参数列表失败: ' + error.message)
    })

  } catch (e) {
    ElMessage.error('网络异常')
  }
}

const handleClose = () => {
  emit('update:visible', false)
}
</script>
